/******主场景加载*******/
!function () {
    
    addSceneCtr("inner");

} ();


//飞行
function flyTo(lon, lat, heading, tilt, altitude){
    var sceneView = new SceneView();
    sceneView.flyTo(lon, lat, heading, tilt, altitude);
};

/******工具选择*******/
var flyno = true;
function setTool(id){
    var sceneControl = new SceneControl();
	var toolManager = sceneControl.toolsManager();
    if(flyno){
        flyTo(113.103843828, 29.347599588, 0, 0, 500);//飞向城市模型
        flyno = false;
    }
	switch(id)
    {
    case "SelectionForEntire":
         var tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 var tool = toolManager.CreateSelectionTool()
         toolManager.setCurrentTool(tool);//模型选择
         sceneControl.AttachEvent("OnAfterSceneObjectSelected", modelEdit);
        break;
    case "SelectionForSection":
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
	     tool = toolManager.CreateSelectionSectionTool();
         toolManager.setCurrentTool(tool);//部件选择
         break;
	case "Measure3DPoint":
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateMeasurePointTool();
		 toolManager.setCurrentTool(tool);//点测量
         break;
    case "Measure3DLineLength" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateMeasureLengthTool();
         toolManager.setCurrentTool(tool);//线测量
         break;
	case "Measure3DClampLength" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateMeasureLengthTool();
		 tool.MeasureStyle = 2;
         toolManager.setCurrentTool(tool);//贴地线测量
         break;
    case "Measure3DRightAngle" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateMeasureRightAngleTool();
         toolManager.setCurrentTool(tool);//直角测量
         break;
    case "Measure3DCircleArea" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateMeasureAreaTool();
		 tool.MeasureAreaType = 1;
         toolManager.setCurrentTool(tool);//圆面积测量
         break;
    case "Measure3DPolygonArea" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateMeasureAreaTool();
         toolManager.setCurrentTool(tool);//多边形面积测量
         break;
	case "Analysis3DFlood" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateRegionFloodTool();
         toolManager.setCurrentTool(tool);//淹没分析
         break;
	case "Analysis3DSection" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateAnalysisSectionTool();
         toolManager.setCurrentTool(tool);//断面分析
         break;
    case "Hollow" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateGeologyAnalysisAreaTool();
         tool.SetGeoXmlString("<?xml version='1.0' encoding='legacy'?><Geology> <Drill name='ZK1' pos='116.1781390,39.9780674,8.746' water_depth='2.5'><layer name='冲填土' texture='冲填土.jpg' depth='5.1'><Attribute name='岩性描述' value='黄土层' unit=''/><Attribute name='地质年代' value='侏罗纪' unit=''/></layer></Drill></Geology>");
         tool.SetTextureAddr("../SamplesResource/GeoTexture/");
         toolManager.setCurrentTool(tool); //挖坑
         sceneControl.AttachEvent("OnAreaAnalysisSelected", areaSelect);
         break;
    case "Area" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateGeologyAnalysisAreaTool();
		 tool.GeologyAnalysisStyle = 2;
         tool.SetGeoXmlString("<?xml version='1.0' encoding='legacy'?><Geology> <Drill name='ZK1' pos='116.1781390,39.9780674,8.746' water_depth='2.5'><layer name='冲填土' texture='冲填土.jpg' depth='5.1'><Attribute name='岩性描述' value='黄土层' unit=''/><Attribute name='地质年代' value='侏罗纪' unit=''/></layer></Drill></Geology>");
         tool.SetTextureAddr("../SamplesResource/GeoTexture/");
         toolManager.setCurrentTool(tool);  //面剖切
         break;
    case "Line" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateGeologyAnalysisLineTool();
         toolManager.setCurrentTool(tool);   //线剖切
         break;
    case "Point2Point" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateAnalysis3DVisibilityTool();         
         toolManager.setCurrentTool(tool);   //点对点
         break; 
    case "Point2Line" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateAnalysis3DVisibilityTool();
         tool.Analysis3DVisibilityStyle = 1;
         toolManager.setCurrentTool(tool);   //点对线
         break;  
    case "Point2Area" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
		 tool = toolManager.CreateAnalysis3DVisibilityTool();
         tool.Analysis3DVisibilityStyle = 2;
         toolManager.setCurrentTool(tool);   //点对面
         break;      
    case "SS_NULL" :
         tol = toolManager.GetCurrentTool();
         if(tol){
             toolManager.DestoryTool(tol);
         }
         toolManager.ClearTool();    //清除剖切
         break;
    }
};

/***** 监听测试程序********/

function modelEdit(id,model,layer,name){
    alert(id);
    var lay = model.GetOwnerLayer();
    model.SetComponentTransparent(true,model.Name,0.1);
    var na = lay.Name;
    alert(na);
};

function areaSelect(isSelected, Material, floorHeight){
    if(isSelected){
        alert("选中 ： " + Material + " 厚度 ：" + floorHeight);
    }
};
